﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineAuction.Business;
using OnlineAuction.Entity;

namespace OnlineAuction.Admin
{
    public partial class ViewCategory : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["UserInfo"] == null
                || Request.Cookies["UserInfo"]["Role"].ToString().CompareTo("Admin") != 0)
            {
                Response.Redirect("../Home.aspx");
            }
            else if (!Page.IsPostBack)
            {
                //Get all item selling by user logged in
                CategoryBO bo = new CategoryBO();
                List<CategoryE> list = bo.ViewCategorys();
                cpCategorySelling.PageSize = 10;
                cpCategorySelling.ShowFirstLast = true;
                cpCategorySelling.DataSource = list;
                cpCategorySelling.BindToControl = grvCategory;
                grvCategory.DataSource = cpCategorySelling.DataSourcePaged;
            }
        }

        protected void grvCategory_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                CategoryBO bo = new CategoryBO();
                bo.DelelteCategory(Convert.ToInt32(e.CommandArgument));
                Response.Redirect("ViewCategory.aspx");
            }
        }

        protected void grvCategory_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }

        public String State(Boolean bl)
        {
            String state = "";

            if (bl == false)
            {
                state = "Disable";
            }
            else
            {
                state = "Enable";
            }
            return state;
        }
    }
}